package com.minimalist.lindi.controller;

import com.minimalist.common.entity.lindi.vo.tradeapplicationoperator.LindiTradeApplicationOperatorVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiTradeApplicationOperatorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_交易申请操作管理")
@RequestMapping("/lindi/tradeApplicationOperator")
public class LindiTradeApplicationOperatorController{

    @Autowired
    private LindiTradeApplicationOperatorService service;

    @PostMapping("/addTradeApplicationOperator")
    @Operation(summary = "添加交易申请操作")
    public R<?> addTradeApplicationOperator(
            @RequestBody @Validated(Add.class)
            LindiTradeApplicationOperatorVO operatorVO){
        service.addTradeApplicationOperator(operatorVO);
        return R.ok();
    }

    @DeleteMapping("/deleteTradeApplicationOperatorById")
    @Operation(summary = "删除交易申请操作 -> 根据操作ID删除")
    public R<?> deleteTradeApplicationOperatorByTradeApplicationOperatorId(
            @RequestParam("tradeApplicationOperatorId")
            @NotNull(message = "交易申请操作ID不能为空")
            @Parameter(name = "tradeApplicationOperatorId", required = true, description = "交易申请操作ID")
            Long tradeApplicationOperatorId){
        service.deleteTradeApplicationOperatorByTradeApplicationOperatorId(
                tradeApplicationOperatorId);
        return R.ok();
    }

    @PutMapping("/updateTradeApplicationOperator")
    @Operation(summary = "修改交易申请操作")
    public R<?> updateTradeApplicationOperatorByTradeApplicationOperatorId(
            @RequestBody @Validated(Update.class)
            LindiTradeApplicationOperatorVO operatorVO){
        service.updateTradeApplicationOperatorByTradeApplicationOperatorId(
                operatorVO);
        return R.ok();
    }

    @GetMapping("/getTradeApplicationOperatorsByTradeApplicationId/{tradeApplicationId}")
    @Operation(summary = "根据交易申请ID查询操作记录")
    public R<List<LindiTradeApplicationOperatorVO>>
    getTradeApplicationOperatorsByApplicationId(
            @PathVariable(value = "tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", description = "交易申请ID", required = true)
            Long tradeApplicationId){
        return R.ok(service.getTradeApplicationOperatorsByApplicationId(
                tradeApplicationId));
    }
}